import { resolveToken } from '../_utils'

const token = {
  admin: 'admin',
  editor: 'editor',
}

export default [
  {
    url: '/api/auth/login',
    method: 'post',
    response: ({ body }) => {
      let { name, password } = body
      if (!['admin', 'editor'].includes(name)) return { code: -1, message: '用户名错误' }
      if (password !== '123456') return { code: -1, message: '密码错误' }
      return {
        code: 0,
        data: {
          token: token[body.name],
        },
      }
    },
  },
  {
    url: '/api/auth/refreshToken',
    method: 'post',
    response: ({ headers }) => {
      return {
        code: 0,
        data: {
          token: resolveToken(headers?.authorization),
        },
      }
    },
  },
  {
    url: '/api/auth/checkIsLockScreen',
    method: 'post',
    response: () => {
      return {
        code: 0,
        data: {
          isLock: true,
        },
      }
    },
  },
  {
    url: '/api/auth/unLockScreen',
    method: 'post',
    response: ({ body }) => {
      let { password } = body
      if (password !== '123456') return { code: -1, message: '解锁密码错误' }
      return {
        code: 0,
        data: {
          unlock: true,
        },
      }
    },
  },
]
